﻿package plugin.union.game
{
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.consts.*;
    import com.sh.game.global.*;
    import com.sh.game.net.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.newteam.model.*;
    import plugin.union.*;
    import uiresource.union.*;
    import view.message.*;

    public class UnionInfoGame extends UnionInfoUI implements IPage
    {
        private var isOnline:int = 0;
        private var selfMsg:Object;
        private var selectInfo:Object;
        private var fuhuizhangCount:int = 0;
        private var jingyingCount:int = 0;

        public function UnionInfoGame()
        {
            this.initEvent();
            txt_desc.toolTip = "1.捐献金币或装备会增加行会资金\n" + "2.行会资金满后会自动升级\n3.每日通过捐献装备获得的行会资金有上限，超过上限则无法积累资金\n" + "4.行会等级越高，每日捐献装备可获得的行会资金越多\n" + "5.捐献金币可获得的行会资金，捐献金币无每日上限\n" + "6.行会每日会自动扣除一定的行会资金以维持行会功能\n" + "7.行会资金为负数不会影响行会功能\n" + "8.在合服之后，资金仍为负数的行会会被系统自动解散 ";
            return;
        }// end function

        private function initEvent() : void
        {
            btn_apply.clickHandler = new Handler(this.ToShowApply);
            cb_state.clickHandler = new Handler(this.changeState);
            cb_auto.clickHandler = new Handler(this.changeAuto);
            btn_donation.clickHandler = new Handler(this.toDonation);
            menu.addEventListener(MouseEvent.MOUSE_DOWN, this.doDown);
            zw.addEventListener(MouseEvent.MOUSE_DOWN, this.doDown);
            GlobalLayer.instance.root.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            btn_chat.clickHandler = new Handler(this.toChat);
            btn_store.clickHandler = new Handler(this.toStore);
            return;
        }// end function

        private function toStore() : void
        {
            ModelProxy.change("plugin", "open", {target:"exchangeshop", data:3});
            return;
        }// end function

        private function toChat() : void
        {
            ModelProxy.change("plugin", "open", {target:"unionChat"});
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            menu.visible = false;
            zw.visible = false;
            return;
        }// end function

        private function toDonation() : void
        {
            ModelProxy.change("union", "todonation", null);
            return;
        }// end function

        private function changeAuto() : void
        {
            UnionSender._17autoAddSet(int(cb_auto.selected));
            return;
        }// end function

        private function changeState() : void
        {
            this.isOnline = int(cb_state.selected);
            this.refreshMemberList();
            return;
        }// end function

        private function ToShowApply() : void
        {
            UnionSender._13showApply();
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_1:* = ModelProxy.getValue("data", "unionInfo");
            cb_auto.selected = Boolean(_loc_1.autoAgree);
            cb_state.selected = Boolean(this.isOnline);
            txt_name.text = _loc_1.unionName;
            txt_level.text = _loc_1.unionLevel;
            txt_time.text = TimeDataFormatUtil.getTimeStr(_loc_1.createTime);
            txt_master.text = _loc_1.unionMaster;
            txt_rank.text = _loc_1.unionRank > 0 ? (_loc_1.unionRank) : ("暂未更新");
            this.refreshMemberList();
            var _loc_2:* = ConfigDictionary.data.union;
            var _loc_3:* = _loc_2[(_loc_1.unionLevel - 1)].money;
            var _loc_4:* = _loc_3 - _loc_1.unionMoney;
            txt_goal.text = (_loc_4 > 0 ? (_loc_4) : (0)) + "行会资金";
            txt_value.text = (_loc_4 >= 0 ? (_loc_1.unionMoney) : (_loc_3)) + "/" + _loc_3;
            TweenLite.to(img_bar, 1, {width:_loc_4 >= 0 ? (133 * _loc_1.unionMoney / _loc_3) : (133)});
            txt_curGold.text = "当前行会资金：" + _loc_1.unionMoney;
            txt_curlevel.text = _loc_1.unionLevel;
            return;
        }// end function

        public function refreshMemberList() : void
        {
            var _loc_5:Object = null;
            var _loc_1:* = ModelProxy.getValue("data", "unionInfo");
            var _loc_2:* = _loc_1.memberList;
            var _loc_3:Array = [];
            var _loc_4:* = UserData.getUserData("name");
            var _loc_6:int = 0;
            this.jingyingCount = 0;
            this.fuhuizhangCount = _loc_6;
            for each (_loc_5 in _loc_2)
            {
                
                if (_loc_5.online >= this.isOnline)
                {
                    _loc_3.push(_loc_5);
                }
                if (_loc_4 == _loc_5.name)
                {
                    this.selfMsg = _loc_5;
                }
                if (_loc_5.title == 10)
                {
                    var _loc_8:String = this;
                    var _loc_9:* = this.fuhuizhangCount + 1;
                    _loc_8.fuhuizhangCount = _loc_9;
                    continue;
                }
                if (_loc_5.title == 5)
                {
                    var _loc_8:String = this;
                    var _loc_9:* = this.jingyingCount + 1;
                    _loc_8.jingyingCount = _loc_9;
                }
            }
            var _loc_6:* = this.selfMsg.title >= 10;
            cb_auto.visible = this.selfMsg.title >= 10;
            btn_apply.visible = _loc_6;
            _loc_3 = UnionUtil.memberShort(_loc_3).members;
            list_member.array = _loc_3;
            list_member.renderHandler = new Handler(this.memberRender);
            return;
        }// end function

        private function memberRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:MemberItemUI = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            if (param2 < list_member.length)
            {
                _loc_3 = list_member.array[param2];
                _loc_4 = param1 as MemberItemUI;
                if (_loc_3.tequan > 0)
                {
                    _loc_4.img_vip.url = "cs2_NewUnion/vip" + _loc_3.tequan + ".png";
                    _loc_4.img_vip.visible = true;
                }
                else
                {
                    _loc_4.img_vip.visible = false;
                }
                _loc_4.txt_name.text = _loc_3.name;
                _loc_4.txt_level.text = _loc_3.level + "级";
                _loc_4.txt_career.text = UIGlobel.getCareer(_loc_3.career);
                if (_loc_3.outTime == 0)
                {
                    if (_loc_3.online)
                    {
                        _loc_4.txt_gx.text = "在线";
                    }
                    else
                    {
                        _loc_4.txt_gx.text = "";
                    }
                }
                else
                {
                    _loc_5 = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
                    _loc_6 = _loc_5 - _loc_3.outTime;
                    if (_loc_6 < 3600)
                    {
                        _loc_4.txt_gx.text = "小于一小时";
                    }
                    else if (_loc_6 >= 86400)
                    {
                        _loc_4.txt_gx.text = int(_loc_6 / 86400) + "天";
                    }
                    else
                    {
                        _loc_4.txt_gx.text = int(_loc_6 / 3600) + "小时";
                    }
                }
                switch(int(_loc_3.title))
                {
                    case 0:
                    {
                        _loc_4.txt_position.text = "<font color=\'#c39e69\'>会员</font>";
                        break;
                    }
                    case 5:
                    {
                        _loc_4.txt_position.text = "<font color=\'#52b631\'size=\'13\'><b>精英</b></font>";
                        break;
                    }
                    case 10:
                    {
                        _loc_4.txt_position.text = "<font color=\'#8c8ee7\'size=\'14\'><b>副会长</b></font>";
                        break;
                    }
                    case 15:
                    {
                        _loc_4.txt_position.text = "<font color=\'#ef8a18\' size=\'15\'><b>会长</b></font>";
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                if (_loc_3.stageId > 0)
                {
                    _loc_4.txt_gz.text = ConfigDictionary.data.maplist[_loc_3.stageId].name;
                }
                else
                {
                    _loc_4.txt_gz.text = "未知";
                }
                param1.disabled = !_loc_3.online;
                param1.mouseEnabled = true;
                param1.removeEventListener(MouseEvent.CLICK, this.showMenu);
                param1.addEventListener(MouseEvent.CLICK, this.showMenu);
            }
            return;
        }// end function

        protected function showMenu(event:MouseEvent) : void
        {
            var _loc_3:Array = null;
            var _loc_2:* = event.currentTarget.dataSource;
            if (_loc_2.name == UserData.getUserData("name"))
            {
                return;
            }
            this.selectInfo = _loc_2;
            switch(this.selfMsg.title)
            {
                case 15:
                case 10:
                {
                    if (_loc_2.title >= this.selfMsg.title)
                    {
                        _loc_3 = ["查看资料", "发起私聊", "发起交易", "发起组队", "加为好友"];
                    }
                    else
                    {
                        _loc_3 = ["查看资料", "发起私聊", "发起交易", "发起组队", "加为好友", "驱逐会员", "任命官爵"];
                    }
                    break;
                }
                default:
                {
                    _loc_3 = ["查看资料", "发起私聊", "发起交易", "发起组队", "加为好友"];
                    break;
                    break;
                }
            }
            menu.x = mouseX;
            menu.y = mouseY;
            list_select.array = _loc_3;
            list_select.renderHandler = new Handler(this.menuHandler, [list_select]);
            selectBg.height = 19 * _loc_3.length - 1;
            menu.visible = true;
            return;
        }// end function

        private function menuHandler(param1:List, param2:Component, param3:int) : void
        {
            var _loc_4:Label = null;
            if (param3 < param1.length)
            {
                _loc_4 = param2.getChildByName("txt") as Label;
                _loc_4.text = param1.array[param3];
                param2.addEventListener(MouseEvent.CLICK, this.doClick);
            }
            return;
        }// end function

        protected function doClick(event:MouseEvent) : void
        {
            var e:* = event;
            var msg:* = e.currentTarget.dataSource;
            switch(msg)
            {
                case "查看资料":
                {
                    Server.instance.send(114, 7, this.selectInfo.rid, 0, ConnectType.SYSTEM);
                    break;
                }
                case "发起私聊":
                {
                    ModelProxy.change("chat", "pritalk", this.selectInfo);
                    break;
                }
                case "发起交易":
                {
                    ModelProxy.change("plugin", "sendSysMsg", {name:"business", param:this.selectInfo.rid, cmd:1});
                    break;
                }
                case "发起组队":
                {
                    PluginManager.instance.sendToServer("team", CMDteam.TEAM_INVITE, this.selectInfo.rid);
                    break;
                }
                case "加为好友":
                {
                    PluginManager.instance.sendToServer("social", 2, this.selectInfo.rid);
                    break;
                }
                case "驱逐会员":
                {
                    UnionSender._43removeMember(this.selectInfo.rid);
                    break;
                }
                case "会长":
                {
                    Alert2.show("确定将会长职位转让?\nPS:转让会长,会让沙巴克城主称号消失", "温馨提示", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    UnionSender._44changePosition(selectInfo.rid, 15);
                }
                return;
            }// end function
            );
                    break;
                }
                case "副会长":
                {
                    if (this.selectInfo.title == 10)
                    {
                        WarningManager.show(9);
                        break;
                    }
                    if (this.fuhuizhangCount >= 3)
                    {
                        WarningManager.show(11);
                    }
                    else
                    {
                        UnionSender._44changePosition(this.selectInfo.rid, 10);
                    }
                    break;
                }
                case "精英":
                {
                    if (this.selectInfo.title == 5)
                    {
                        WarningManager.show(9);
                        break;
                    }
                    if (this.fuhuizhangCount >= 30)
                    {
                        WarningManager.show(10);
                    }
                    else
                    {
                        UnionSender._44changePosition(this.selectInfo.rid, 5);
                    }
                    break;
                }
                case "会员":
                {
                    if (this.selectInfo.title == 0)
                    {
                        WarningManager.show(9);
                        break;
                    }
                    UnionSender._44changePosition(this.selectInfo.rid, 0);
                    break;
                }
                case "任命官爵":
                {
                    zw.visible = true;
                    zw.x = menu.x + 95;
                    zw.y = menu.y;
                    if (this.selfMsg.title > 10)
                    {
                        list_select2.array = ["会长", "副会长", "精英", "会员"];
                    }
                    else
                    {
                        list_select2.array = ["精英", "会员"];
                    }
                    list_select2.renderHandler = new Handler(this.menuHandler, [list_select2]);
                    selectBgzw.height = list_select2.length * 19;
                    return;
                }
                default:
                {
                    break;
                }
            }
            zw.visible = false;
            menu.visible = false;
            return;
        }// end function

        protected function doDown(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            return;
        }// end function

    }
}
